home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / acpi-support / power-funcs < prev    next >
Text File  |  2009-10-13  |  1KB  |  60 lines

  1. # a micro library of helper functions for the power scripts
  2.  
  3. umask 022;
  4.  
  5. PATH="$PATH:/usr/bin/X11"
  6. POWERSTATE="/var/lib/acpi-support/powerstate"
  7.  
  8. getXuser() {
  9.         user=`finger| grep -m1 ":$displaynum " | awk '{print $1}'`
  10.     if [ x"$user" = x"" ]; then
  11.         user=`finger| grep -m1 ":$displaynum" | awk '{print $1}'`
  12.     fi
  13.     if [ x"$user" != x"" ]; then
  14.             userhome=`getent passwd $user | cut -d: -f6`
  15.             export XAUTHORITY=$userhome/.Xauthority
  16.     else
  17.         export XAUTHORITY=""
  18.     fi
  19. }
  20.  
  21. getXconsole() {
  22.     console=`fgconsole`;
  23.     displaynum=`ps t tty$console | sed -n -re 's,.*/X .*:([0-9]+).*,\1,p'`
  24.     if [ x"$displaynum" != x"" ]; then
  25.         export DISPLAY=":$displaynum"
  26.         getXuser
  27.     fi
  28. }
  29.  
  30. getState() {
  31.         /usr/bin/on_ac_power
  32.         if [ "$?" -eq 1 ]; then
  33.                 STATE="BATTERY"
  34.         else
  35.                 STATE="AC"
  36.         fi
  37. }
  38.         
  39. #check our state has actually changed
  40. checkStateChanged() {
  41. # do we have our state stashed?
  42.         if [ -f "$POWERSTATE" ]; then
  43.                 OLDSTATE=$(<$POWERSTATE) 
  44.                 if [ "$STATE" = "$OLDSTATE" ]; then
  45.                        exit 0
  46.                 else
  47. #stash the new state
  48.                         echo "$STATE" > $POWERSTATE
  49.                 fi
  50.         else
  51. #we need to stash the new state
  52.                 echo "$STATE" > $POWERSTATE
  53.         fi
  54. }
  55.  
  56. LAPTOP_MODE='/usr/sbin/laptop_mode'
  57. HDPARM='/sbin/hdparm -q'
  58.  
  59. LIDSTATE='/var/lib/acpi-support/lidstate'
  60.